package net.m510.autosurfer.aeoncard;

import java.net.URI;
import java.util.List;
import java.util.logging.Logger;

import net.m510.autosurfer.common.DocumentPostProcess;
import net.m510.autosurfer.common.exception.InvalidDocumentException;
import net.m510.autosurfer.core.Parameters;
import net.m510.autosurfer.core.utils.AnalyzeUtils;

import org.apache.http.NameValuePair;
import org.apache.http.client.protocol.HttpClientContext;
import org.apache.http.impl.client.CloseableHttpClient;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.nodes.FormElement;

public class AeonCardCreditDatail extends DocumentPostProcess {
	private static final Logger log = Logger.getLogger(AeonCardCreditDatail.class.getName());

	public AeonCardCreditDatail() {
		this(null,null);
	}
	
	public AeonCardCreditDatail(CloseableHttpClient client,HttpClientContext context) {
		super(client, context);
		super.log = log;
	}

	private static final String FORM_ID="bridgeToCreditFuncForm";
	@Override
	protected URI getUri(Document doc) {
		Element e = AnalyzeUtils.getFormElementById(doc, FORM_ID);
		if ( e == null ) throw new InvalidDocumentException("form not found id="+FORM_ID, doc);
		return AnalyzeUtils.resolveURIByFormAction(context, e);
	}

	@Override
	protected List<NameValuePair> getRequestParameters(Document doc) {
		FormElement form = AnalyzeUtils.getFormElementById(doc, FORM_ID);
		Parameters p = Parameters.create(form);
		p.put("transferId", "detailInquiry");
		p.put("mainCardFlg", "1");
		p.put("subCardSequence", "");
		return p.asNameValueList();
	}
}
